import { request } from '@/utils'

// 获取角色列表
export const getRoles = (params) => {
  return request({
    url: '/roles',
    method: 'get',
    params
  });
};

// 添加角色
export const addRole = (data) => {
  return request({
    url: '/roles',
    method: 'post',
    data
  });
};

// 更新角色
export const updateRole = (id, data) => {
  return request({
    url: `/roles/${id}`,
    method: 'put',
    data
  });
};

// 删除角色
export const deleteRole = (id) => {
  return request({
    url: `/roles/${id}`,
    method: 'delete'
  });
};
// 获取所有权限
export const getAllPermissions = () => {
  return request({
    url: '/permissions',
    method: 'get'
  });
};

// 获取权限列表
export const getPermissions = (roleId = null) => {
  const url = roleId ? `/roles/${roleId}/permissions` : '/permissions';
  return request({
    url: url,
    method: 'get'
  });
};

// 分配权限
export const assignPermissions = (roleId, data) => {
  return request({
    url: `/roles/${roleId}/permissions`,
    method: 'post',
    data
  });
};

// 分配菜单
export const assignMenus = (roleId, data) => {
  return request({
    url: `/roles/${roleId}/menus`,
    method: 'post',
    data
  });
};

// 获取角色菜单
export const getRoleMenusById = (roleId) => {
  return request({
    url: `/roles/${roleId}/menus`,
    method: 'get'
  });
};

